﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using qiupeng.Public;
using System.IO;

public partial class SystemManage_SysData : System.Web.UI.Page
{
    Db List = new Db();
        public static string CountsLabel, AllPageLabel, CurrentlyPageLabel, SqlStrStart, SqlStrMid, SqlStr, SqlStrStartCount, SqlStrCount, type, typename;
        public string CreateMidSql()
        {
            string MidSql = string.Empty;
            if (Request.QueryString["key"] != null)
            {
                if (Request.QueryString["Name"] != null)
                {
                    MidSql = MidSql + " and Name like '%" + List.GetFormatStr(Server.UrlDecode(Request.QueryString["Name"])) + "%'";
                }
            }
            return MidSql;

        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.Session["username"] == null)
            {
                this.Response.Write("<script language=javascript>alert('登陆超时！');window.parent.location = '../main_d.aspx'</script>");
                return;

            }

            if (!Page.IsPostBack)
            {
                type = base.Request.QueryString["type"].ToString();
                if (type == "1")
                {
                    typename = "学历";
                }
                if (type == "2")
                {
                    typename = "事故类型";
                }
                if (type == "3")
                {
                    typename = "执业资格";
                }
                if (type == "4")
                {
                    typename = "工资项目";
                }
                if (type == "5")
                {
                    typename = "班次类型";
                }
                if (type == "6")
                {
                    typename = "休假类型";
                }
                if (type == "7")
                {
                    typename = "伤害部位";
                }
                if (type == "8")
                {
                    typename = "婚姻状况";
                }
                if (type == "9")
                {
                    typename = "健康状况";
                }
                if (type == "10")
                {
                    typename = "伤害程度";
                }
                if (type == "11")
                {
                    typename = "协议类型";
                }
                if (type == "12")
                {
                    typename = "在职状态";
                }
                if (type == "13")
                {
                    typename = "事故级别";
                }
                if (type == "14")
                {
                    typename = "课件类别";
                }
                if (type == "15")
                {
                    typename = "非伤亡事故类别";
                }
                if (type == "16")
                {
                    typename = "人才等级";
                }
                if (type == "17")
                {
                    typename = "培训类型";
                }
                if (type == "18")
                {
                    typename = "流程操作";
                }
                if (type == "19")
                {
                    typename = "招聘来源";
                }
                if (type == "20")
                {
                    typename = "面试方式";
                }
                if (type == "21")
                {
                    typename = "行业性质";
                }
                if (type == "22")
                {
                    typename = "企业性质";
                }
                if (type == "23")
                {
                    typename = "合同变更";
                }
                if (type == "24")
                {
                    typename = "奖励项目";
                }
                if (type == "25")
                {
                    typename = "处分项目";
                }
                if (type == "26")
                {
                    typename = "离职原因";
                }
                if (type == "27")
                {
                    typename = "人才分类";
                }
                if (type == "28")
                {
                    typename = "管理级别";
                }
                if (type == "29")
                {
                    typename = "籍贯";
                }
                if (type == "30")
                {
                    typename = "初选方式";
                }
                if (type == "31")
                {
                    typename = "培训计划年份";
                }
                if (type == "32")
                {
                    typename = "培训方式";
                }
                if (type == "33")
                {
                    typename = "课件类别";
                }
                if (type == "34")
                {
                    typename = "授课方式";
                }
                if (type == "35")
                {
                    typename = "培训方法";
                }
                if (type == "36")
                {
                    typename = "协议类型";
                }
                if (type == "37")
                {
                    typename = "培训协议年份";
                }
                if (type == "38")
                {
                    typename = "事故类别";
                }
                if (type == "39")
                {
                    typename = "合同类型";
                }
                if (type == "40")
                {
                    typename = "合同解除类别";
                }
                if (type == "41")
                {
                    typename = "合同恢复类别";
                }
                if (type == "42")
                {
                    typename = "合同试用类别";
                }
                if (type == "43")
                {
                    typename = "合同转正类别";
                }
                if (type == "44")
                {
                    typename = "合同变更类别";
                }
                if (type == "45")
                {
                    typename = "合同续签类别";
                }
                if (type == "46")
                {
                    typename = "三违种类";
                }
                if (type == "47")
                {
                    typename = "员工工种";
                }
                if (type == "48")
                {
                    typename = "调动类型";
                }
                if (type == "49")
                {
                    typename = "离职类型";
                }
                if (type == "50")
                {
                    typename = "复职类型";
                }
                if (type == "51")
                {
                    typename = "证照类型";
                }
                if (type == "52")
                {
                    typename = "发证机构";
                }
                if (type == "53")
                {
                    typename = "职称取得方式";
                }
                if (type == "54")
                {
                    typename = "考核类型";
                }
                if (type == "55")
                {
                    typename = "考核期间";
                }
                if (type == "56")
                {
                    typename = "开户行";
                }
                if (type == "57")
                {
                    typename = "职位类别";
                }
                if (type == "98")
                {
                    typename = "政治面貌";
                }
                if (type == "97")
                {
                    typename = "员工岗位";
                }
                if (type == "96")
                {
                    typename = "员工职务";
                }
                if (type == "95")
                {
                    typename = "员工职称";
                }
                if (type == "94")
                {
                    typename = "惩罚类别";
                }
                this.BindAttribute();
                this.DataBindToGridview("order by id asc");
                this.Bindquanxian();

            }
        }
        public void Bindquanxian()
        {
            //List.QuanXianVis(ImageButton1, "iiii7b", Session["perstr"].ToString());

            //List.QuanXianVis(ImageButton2, "iiii7d", Session["perstr"].ToString());
            //List.QuanXianVis(ImageButton3, "iiii7e", Session["perstr"].ToString());
            //List.QuanXianVis(IMG1, "iiii7i", Session["perstr"].ToString());

        }
        public void BindAttribute()
        {
            ImageButton2.Attributes["onclick"] = "javascript:return updatecheck();";
            ImageButton1.Attributes["onclick"] = "javascript:return showwait();";
            ImageButton3.Attributes["onclick"] = "javascript:return delcheck();";




            btnFirst.Attributes["onclick"] = "javascript:return showwait();";
            btnPrev.Attributes["onclick"] = "javascript:return showwait();";
            btnNext.Attributes["onclick"] = "javascript:return showwait();";
            btnLast.Attributes["onclick"] = "javascript:return showwait();";
            Button1.Attributes["onclick"] = "javascript:return chkyema();";
        }
        public void DataBindToGridview(string Sqlsort)
        {
            SqlStrStart = "select * from qp_hr_SysData where type='" + base.Request.QueryString["type"] + "' and  1=1";
            SqlStrStartCount = "select count(id) from qp_hr_SysData where type='" + base.Request.QueryString["type"] + "' and 1=1";
            SqlStrMid = string.Empty;
            SqlStrMid = this.CreateMidSql();
            SqlStr = SqlStrStart + SqlStrMid;
            SqlStrCount = SqlStrStartCount + SqlStrMid;
            if (base.Request.QueryString["key"] != null)
            {
                string sql = SqlStr + " " + Sqlsort;
                this.GridView1.DataSource = this.List.GetGrid_Pages_not(sql);
                this.GridView1.DataBind();
                string sqlStrCount = SqlStrCount;
                CountsLabel = Convert.ToString(this.List.GetCount(sqlStrCount));
            }
            else
            {
                string str3 = "select count(id) from  qp_hr_SysData where type='" + base.Request.QueryString["type"] + "'";
                CountsLabel = Convert.ToString(this.List.GetCount(str3));
                string str4 = "select * from qp_hr_SysData where type='" + base.Request.QueryString["type"] + "' " + Sqlsort;
                this.GridView1.DataSource = this.List.GetGrid_Pages_not(str4);
                this.GridView1.DataBind();
            }
            AllPageLabel = Convert.ToString(this.GridView1.PageCount);
            CurrentlyPageLabel = Convert.ToString((int)(this.GridView1.PageIndex + 1));
            this.btnFirst.CommandName = "1";
            this.btnPrev.CommandName = (this.GridView1.PageIndex == 0) ? "1" : this.GridView1.PageIndex.ToString();
            this.btnNext.CommandName = (this.GridView1.PageCount == 1) ? this.GridView1.PageCount.ToString() : ((this.GridView1.PageIndex + 2)).ToString();
            this.btnLast.CommandName = this.GridView1.PageCount.ToString();

        }










        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            DataControlRowType itemType = e.Row.RowType;
            if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes["onmouseover"] = "javascript:setMouseOverColor(this);";
                e.Row.Attributes["onmouseout"] = "javascript:setMouseOutColor(this);";

            }



        }
        private string CheckCbxDel()
        {
            string str = "0";
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                GridViewRow row = GridView1.Rows[i];
                CheckBox Chk = (CheckBox)row.FindControl("CheckSelect");
                Label LabVis = (Label)row.FindControl("LabVisible");
                if (Chk.Checked == true)
                {
                    if (str == "")
                    {
                        str = LabVis.Text.ToString();
                    }
                    else
                    {
                        str = str + "," + LabVis.Text.ToString();
                    }
                }
            }
            return str;
        }


        private string CheckCbxNameDel()
        {
            string str = string.Empty;
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                GridViewRow row = GridView1.Rows[i];
                CheckBox Chk = (CheckBox)row.FindControl("CheckSelect");
                Label LabVis = (Label)row.FindControl("LabNameVisible");
                if (Chk.Checked == true)
                {
                    if (str == "")
                    {
                        str = LabVis.Text.ToString();
                    }
                    else
                    {
                        str = str + "," + LabVis.Text.ToString();
                    }
                }
            }
            return str;
        }

        private string CheckCbxUpdate()
        {
            string str = string.Empty;
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                GridViewRow row = GridView1.Rows[i];
                CheckBox Chk = (CheckBox)row.FindControl("CheckSelect");
                Label LabVis = (Label)row.FindControl("LabVisible");
                if (Chk.Checked == true)
                {
                    if (str == "")
                    {
                        str = LabVis.Text.ToString();
                    }
                    else
                    {
                        str = str + "," + LabVis.Text.ToString();
                    }
                }
            }
            return str;
        }



        protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
        {
            string sql = "";

            if (ViewState["SortDirection"] == null || ViewState["SortDirection"].ToString().CompareTo("") == 0)
            {
                ViewState["SortDirection"] = " asc";
            }
            else
                ViewState["SortDirection"] = "";

            sql = " order by " + e.SortExpression + ViewState["SortDirection"];


            DataBindToGridview(sql);
        }





        public override void VerifyRenderingInServerForm(Control control)
        { }

        protected void PagerButtonClick(object sender, EventArgs e)
        {
            try
            {
                GridView1.PageIndex = Convert.ToInt32(((LinkButton)sender).CommandName) - 1;
                DataBindToGridview("order by id asc");
            }
            catch
            {
                Response.Write("<script language='javascript'>alert('没有这么多页！');</script>");
                return;
            }
        }

        protected void Button1_Click1(object sender, EventArgs e)
        {
            try
            {
                if (GoPage.Text.Trim().ToString() == "")
                {
                    Response.Write("<script language='javascript'>alert('页码不可以为空!');</script>");
                }
                else if (GoPage.Text.Trim().ToString() == "0" || Convert.ToInt32(GoPage.Text.Trim().ToString()) > GridView1.PageCount)
                {
                    Response.Write("<script language='javascript'>alert('页码不是一个有效值!');</script>");
                }
                else if (GoPage.Text.Trim() != "")
                {
                    int PageI = Int32.Parse(GoPage.Text.Trim()) - 1;
                    if (PageI >= 0 && PageI < (GridView1.PageCount))
                    {
                        GridView1.PageIndex = PageI;
                    }
                }
                DataBindToGridview("order by id asc");
            }
            catch
            {
                DataBindToGridview("order by id asc");
                Response.Write("<script language='javascript'>alert('请输入有效的页码字符！');</script>");
            }
        }

        protected void ImageButton3_Click(object sender, ImageClickEventArgs e)
        {
            string CheckStr = CheckCbxDel();


            string SqlStr = "  Delete from qp_hr_SysData  where ID in (" + CheckStr + ")";
            List.ExeSql(SqlStr);

            List.InsertLog("删除基础数据[" + CheckCbxNameDel() + "]", "系统管理-基础数据-" + typename + "");

            DataBindToGridview("order by id asc");




        }

        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {

            Response.Redirect("SysData_update.aspx?type=" + type + "&id=" + CheckCbxUpdate() + "");

        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("SysData_add.aspx?type=" + type + "&");
        }




}
